package com.guli.cart.service.impl;
/*
 * @Author 罗俊
 * @date 2020/11/2 - 9:04 上午
 *
 */

import com.guli.cart.service.OffLineCartService;
import com.guli.common.pojo.vo.SkuItemVo;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class OffLineCartServiceImpl implements OffLineCartService {


    @Resource
    StringRedisTemplate stringRedisTemplate;

    @Override
    public void addToPurchaseCart(List<SkuItemVo> skuItems, String userCartOffLine) {


        Map<Long, SkuItemVo> itemMap = skuItems.stream().collect(Collectors.toMap(SkuItemVo::getSkuId, skuItem -> {
            return skuItem;
        }));

        HashOperations<String, Long, SkuItemVo> mapOps = stringRedisTemplate.opsForHash();

        mapOps.putAll(userCartOffLine,itemMap);

    }
}
